var util = require('../../../../utils/util.js');
var api = require('../../../../config/api.js');

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    orderId: {
      type: Number,
      value: -1,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    problem: "", //问题
    introduction: "", //介绍
    orderInfo:{} //订单数据
  },

  /**
   * 组件的方法列表
   */
  methods: {
    commit: function () {
      var myEventDetail = {
        toUserId: this.data.orderInfo.to_user_id, //导师id
        price: this.data.orderInfo.price, //价钱
        meetType: this.data.orderInfo.meet_type, //越聊方式
        topicId: this.data.orderInfo.topic_id, //购买话题
        question: this.data.problem, //问题
        introduction: this.data.introduction, //自我介绍
        id: this.properties.orderId,
        status:1 //订单状态
      }
      if (myEventDetail.question.length < 1 || myEventDetail.introduction.length < 1) {
        wx.showToast({
          title: "问题/自我介绍为必填项",
          icon: 'none'
        });
        return false;
      } else if (myEventDetail.question.length > 500 || myEventDetail.introduction.length > 500) {
        wx.showToast({
          title: "问题/自我介绍限500字",
          icon: 'none'
        });
      }  else {
        this.triggerEvent('myeventA', myEventDetail);
      }
    },
    inputProblemChange(e) {
      this.setData({
        problem: e.detail.value
      })
    },
    inputIntroductionChange(e) {
      this.setData({
        introduction: e.detail.value
      })
    },
    //请求订单数据
    getOrderInfo(orderNum) {
      let that = this;
      util.request(api.SelectUserOrderByOrderId, {
        id: orderNum
      }, 'GET').then(function (res) {
        if (res.code === 200) {
          that.setData({
            orderInfo:res.result,
            problem: res.result.question,
            introduction: res.result.introduction
          })
        }else{
          wx.showToast({
            title: res.message,
            icon: 'none'
          });
        }
      })
    }
  },
  ready: function (e){
    this.getOrderInfo(this.properties.orderId)
  }

  /*提交触发父组件*/
})